/**
* @description: 108. 将有序数组转换为二叉搜索树
* @author hewei
* @date 2022/7/27 14:54
* @version 1.0
*/

public class SortedArrayToBST {

    int[] nums;
    public TreeNode sortedArrayToBST(int[] nums) {
        this.nums = nums;
        return process(0, nums.length - 1);
    }

    public TreeNode process(int l, int r) {
        if (l > r) return null;

        int mid = (r - l) / 2 + l;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = process(l, mid - 1);
        node.right = process(mid + 1, r);
        return node;
    }
}
